package com.demo.service.impl;

import com.demo.dao.IRoleDao;
import com.demo.dao.IUserRoleDao;
import com.demo.entity.Role;
import com.demo.entity.UserRole;
import com.demo.service.IRoleService;
import com.demo.vo.RolePermissionUnion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements IRoleService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IRoleDao dataDao;
    @Autowired
    private IUserRoleDao userRoleDao;

    @Override
    public List<Role> queryAll() {
        return dataDao.queryAll();
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return dataDao.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Role arg) {
        return dataDao.insert(arg);
    }

    @Override
    public int insertSelective(Role arg) {

        int insert = dataDao.insert(arg);
//        if(insert>0){
//            return dataDao.selectId();
//        }
        return insert;
    }

    @Override
    public Role selectByPrimaryKey(Integer id) {
        return dataDao.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Role record) {



        return dataDao.updateByPrimaryKeySelective(record)
                ;
    }

    @Override
    public List<Role> getRolesByUserID(int userid) {
        return dataDao.getRolesByUserID(userid);
    }

    @Override
    public List<Role> getRoleList(Role role) {
        return dataDao.getRoleList(role);
    }

    @Override
    public List<RolePermissionUnion> queryAllRoleWithPermission() {
        return dataDao.queryAllRoleWithPermission();
    }

    @Override
    public List<Role> getUserRoleByUserId(int userid) {
        return dataDao.getRolesByUserID(userid);
    }

    @Override
    public int queryByRoleId(UserRole userid) {
        return userRoleDao.queryByRoleId(userid);
    }

}
